<template>
	<view class="content">
		<swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
			:duration="duration">
			<swiper-item v-for="item  in list" :key="item.id">
				<view class="swiper-item uni-bg-red">
					<image :src="'http://124.93.196.45:10001/'+item.advImg"></image>
				</view>
			</swiper-item>
		</swiper>

		<uni-grid :column="5" :highlight="true" @change="change">
			<uni-grid-item v-for="(item, index) in serviceList" :index="index" :key="index">
				<view class="grid-item-box" style="background-color: #fff;">

					<image :src="'http://124.93.196.45:10001/'+item.imgUrl" v-if="item.id!=0"></image>
					<uni-icons v-else type="more" size="40"></uni-icons>
					<view class="text">{{item.serviceName}}</view>
				</view>
			</uni-grid-item>
		</uni-grid>
		<view v-for="item  in  newsList" :key="item.id">
			<ui-newsList :newsImage="'http://124.93.196.45:10001/'+item.cover" :newsTitle='item.title'
				:newsCreatTime='item.createTime'></ui-newsList>

		</view>
	</view>
</template>
<script>
	import {
		bannerList,
		serviceQuery
	} from "../../service/homeService.js"
	import {
		newsQuery
	} from "../../service/newsService.js"
	import uiNewsList from "../../uni_modules/ui-newsList/ui-newsList"
	export default {
		components: {
			"ui-newsList": uiNewsList
		},
		data() {
			return {
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				title: 'Hello',
				list: [], //轮播图的集合
				serviceList: [], //服务的集合
				newsList: [], //新闻的集合
				pageNum: 1,
				total: 100
			}
		},
		async created() {
			let res = await bannerList(); //请求轮播
			// console.log(res);
			this.list = res.data.rows;

			let res2 = await serviceQuery(); //请求服务
			let total = res2.data.total;
			if (total <= 10) {
				this.serviceList = res2.data.rows;
			} else {
				this.serviceList = res2.data.rows.splice(0, 9).concat([{
					id: 0,
					serviceName: "更多服务",
					link: "service/service"
				}])
			}
			this.search();


		},
		onLoad() {

		},
		methods: {
			async search() {
				let res3 = await newsQuery({
					pageNum: this.pageNum,
					pageSize: 10
				})
				this.total = res3.data.total;

				this.newsList = [...this.newsList, ...res3.data.rows];


			},

			change(item) {
				let link = this.serviceList[item.detail.index].link;
				if (this.serviceList[item.detail.index].id != 0) {
					uni.navigateTo({
						url: "/pages/" + link
					})

				} else {
					uni.switchTab({
						url: "/pages/" + link
					})
				}
			}
		},
		onReachBottom() {
			if (this.total != this.newsList.length) {
				this.pageNum++;
				this.search();
			}

		}
	}
</script>

<style>
	.swiper {
		height: 300rpx;
		width: 100%;
	}

	.swiper-item {
		display: block;
		height: 300rpx;
		line-height: 300rpx;
		text-align: center;
		width: 100%;
	}

	.swiper-item image {
		width: 100%;
	}

	.grid-item-box {
		display: flex;
		justify-content: center;
		flex-direction: column;
		align-items: center;
		font-size: 12rpx;
	}

	.grid-item-box image {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
	}
</style>
